<!-- eslint-disable vue/multi-word-component-names -->
<template>
    <div id="temperature"></div>
  </template>
  
  <script lang="ts" setup>
  import { onMounted } from "vue";
  import * as echarts from "echarts";
  
  
  onMounted(() => {
    var chartDom = document.getElementById("temperature");
    var myChart = echarts.init(chartDom);
    var option;
  
    const stateData = {
      xAxisData: [
        "06-27",
        "06-28",
        "06-29",
        "06-30",
        "07-01",
        "07-02",
        "07-03",
        "07-04",
      ],
      sgData: [10, 35, 40, 32, 40, 34, 22, 40],
      bgData: [20, 28, 39, 22, 15, 27, 28, 37],
    };
    option = {
      tooltip: {},
      grid: {
          top: "1%",
          left: "10%",
          right: "6%"
      },
      legend: {
        itemWidth: 7,
        itemHeight: 7,
        // itemGap: 15,
        icon: "rect",
        // right: 0,
        textStyle: {
          fontSize: 14,
          fontFamily: "PingFangSC, PingFang SC",
          fontWeight: 400,
        },
      },
      xAxis: {
        type: "category",
        boundaryGap: false,
        data: stateData.xAxisData,
        axisLabel: {
          fontSize: 12,
          fontFamily: "PingFangSC, PingFang SC",
          fontWeight: 400,
          color:"#b6babf"
        },
      },
      yAxis: {
        type: "value",
        data: ["0", "5", "10", "15", "20", "25", "30", "35", "40"],
        nameTextStyle: {
          fontSize: 12,
          fontFamily: "PingFangSC, PingFang SC",
          fontWeight: 400,
        },
        axisLabel: {
          fontSize: 12,
          fontFamily: "PingFangSC, PingFang SC",
          fontWeight: 400,
          color:"#b6babf",
          formatter: '{value}kg',
        },
      },
      series: [
        {
          data: stateData.sgData,
          type: "line",
          smooth: true,
          itemStyle: {
            normal: {
              color: "rgba(255, 116, 133, 1)",
              lineStyle: {
                color: "rgba(255, 116, 133, 1)",
                width: 2,
              },
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                  {
                    offset: 0,
                    color: "rgba(255, 116, 133, 0)",
                  },
                  {
                    offset: 1,
                    color: "rgba(255, 116, 133, 1)",
                  },
                ]),
              },
            },
          },
        },
        {
          data: stateData.bgData,
          type: "line",
          smooth: true,
          itemStyle: {
            normal: {
              color: "rgba(95, 175, 255, 1)",
              lineStyle: {
                color: "rgba(95, 175, 255, 1)",
                width: 2,
              },
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                  {
                    offset: 0,
                    color: "rgba(95, 175, 255, 0)",
                  },
                  {
                    offset: 1,
                    color: "rgba(95, 175, 255, 1)",
                  },
                ]),
              },
            },
          },
        },
      ],
    };
  
    option && myChart.setOption(option);
    //监听窗口变化
    window.addEventListener("resize", function () {
      console.log("监听窗口变化");
      myChart.resize();
    });
  });
  </script>
  
  <style scoped>
  #temperature {
    width: 100%;
    /* height: 20vh; */
    height: 100%;
  }
  </style>